﻿// -------------------------------------------------------------------------
//    @FileName         :    NFActivityEightModule.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-09
//    @Email			:    445267987@qq.com
//    @Module           :    NFActivityEightModule
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFActivityEightModule.h"

#include "NFActivityEightPart.h"
#include "NFActivityEightService.h"
#include "NFPacketSendUtil.h"
#include "NFPlayer.h"
#include "NFSession.h"
#include "proto_cs_cmd.nanopb.h"

NFActivityEightModule::NFActivityEightModule(NFIPluginManager* p) : NFLogicDynamicModule(p)
{
}

NFActivityEightModule::~NFActivityEightModule()
{
}

int NFActivityEightModule::Awake()
{
    RegisterClientMessage(NF_ST_LOGIC_SERVER, E_CS_ACTIVITY_EIGHT_GET_DATE_REQ);
    RegisterClientMessage(NF_ST_LOGIC_SERVER, E_CS_ACTIVITY_EIGHT_GET_RWD_REQ);

    return 0;
}

int NFActivityEightModule::OnHandleClientMessage(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    CHECK_NULL(0, pSession);
    if (!m_pObjPluginManager->IsInited(NF_ST_LOGIC_SERVER))
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server not inited, drop client msg:{}", packet.ToString());
        return -1;
    }

    if (m_pObjPluginManager->IsServerStopping())
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server is Stopping, drop client msg:{}", packet.ToString());
        return ERR_CODE_SERVER_IS_STOPPING;
    }

    int iRetCode = 0;
    switch (packet.nMsgId)
    {
        case E_CS_ACTIVITY_EIGHT_GET_DATE_REQ:
        {
            iRetCode = OnHandleActivityEightGetDataReq(packet, pSession, req);
            break;
        }
        case E_CS_ACTIVITY_EIGHT_GET_RWD_REQ:
        {
            iRetCode = OnHandleActivityEightGetRewardReq(packet, pSession, req);
            break;
        }
        default: NFLogError(NF_LOG_DEFAULT, 0, "not handle msg:{}", packet.nMsgId);
    }

    return iRetCode;
}

int NFActivityEightModule::OnHandleActivityEightGetDataReq(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    CHECK_NULL(0, pSession);

    NFPlayer* pPlayer = pSession->GetPlayer();
    CHECK_NULL(0, pPlayer);

    NFActivityEightPart* pActivityEight = NFActivityEightService::GetActivityEight(pPlayer);
    CHECK_NULL(pPlayer->GetRoleID(), pActivityEight);


    proto_ff::Proto_CSRsp resp;
    proto_ff::Proto_SCActivityGetAllDataRsp* rsp = resp.mutable_activity_eight_get_data_rsp();
    ActivityEightData& actData = pActivityEight->GetData();

    rsp->set_cur_score(actData.cur_score);
    rsp->set_group_id(actData.activity_group);
    rsp->set_activity_start_time(actData.activity_start_time);
    for (int i = 0; i < (int)actData.data.size(); ++i)
    {
        proto_ff::ActivityEightSingleData* tmpData = rsp->add_data();

        tmpData->set_id(actData.data[i].id);
        tmpData->set_count(actData.data[i].param[0]);
        tmpData->set_is_get_rwd(actData.data[i].is_get_rwd);
    }

    for (int i = 0; i < (int)actData.score_rwd.size(); ++i)
    {
        rsp->add_score_rwd(actData.score_rwd[i]);
    }

    return NFPacketSendUtil::SendToClient(pPlayer, proto_ff::E_SC_ACTIVITY_EIGHT_GET_DATE_RSP, &resp);
}

int NFActivityEightModule::OnHandleActivityEightGetRewardReq(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    return 0;
}
